package com.kalua.list.harvester.crawldata;

import java.util.Arrays;
import java.util.Collections;
import java.util.Set;

import com.google.common.collect.Sets;

public class ProductLink {
	private String targetURL;
	private Set<String> metaInformation;
	
	public ProductLink(String targetURL) {
		super();
		this.targetURL = targetURL;
		this.metaInformation = Sets.newConcurrentHashSet();
	}
	
	public String getTargetURL() { return this.targetURL; }
	
	public void addMetaInformation(Set<String> metaInformation) 
	{ this.metaInformation.addAll(metaInformation); }
	public Set<String> getMetaInformation() 
	{ return Collections.unmodifiableSet(this.metaInformation); }
	
	@Override
	public int hashCode() 
	{ return Arrays.hashCode(new String[]{this.targetURL}); }
	
	@Override
	public boolean equals(Object candidate) {
		boolean result = false;
		if (this == candidate)
			result = true;
		else if (candidate!=null && candidate instanceof ProductLink) {
			ProductLink other = (ProductLink) candidate;
			Object[] fields = new Object[] {this.targetURL, this.metaInformation};
			Object[] otherFields = new Object[] {other.targetURL, other.metaInformation};
			result = Arrays.equals(fields, otherFields);					
		}
		return result;
	}
	
	@Override
	public String toString() 
	{ return this.targetURL + "(metaInformation=" + metaInformation.size()+")"; }
}